package com.bac.bacplatform;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.bac.javabeans.Principal;
import com.bac.javabeans.Wallet;
import com.bac.javabeans.WealthAccountJournalProfitStatistic;
import com.bac.utils.Config;
import com.bac.utils.MyWalletListAdapter;
import com.bac.utils.Storage;
import com.bac.utils.Util;
import com.google.gson.Gson;

public class MyWalletActivity extends BaseActivity implements OnClickListener {
	private ListView mlist;
	public static int viewWlenth = 0;
	private Button movein_btn;

	private TextView lastDay;
	private TextView allMoney;
	private TextView meishuju;
	
	private Button mGotoCharge;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.personal_oilwallet);
		viewWlenth = Util.getWidth(this) - 40;
		getWallet();

	}

	@Override
	public void init() {
		lastDay = (TextView) findViewById(R.id.textView2);
		allMoney = (TextView) findViewById(R.id.textView4);
		mlist = (ListView) findViewById(R.id.my_lv);
		meishuju = (TextView) findViewById(R.id.meishuju);
		movein_btn = (Button) findViewById(R.id.movein_btn);
		movein_btn.setOnClickListener(this);
		mGotoCharge = (Button)findViewById(R.id.bt_gocharge);
		mGotoCharge.setOnClickListener(this);
		findViewById(R.id.title_left).setOnClickListener(this);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.movein_btn:
			Intent intentToMoveIn = new Intent(this, MoveInActivity.class);
			startActivityIn(intentToMoveIn);
			break;
		case R.id.title_left:
			finishActivityOut();
			break;
		case R.id.bt_gocharge:
			Intent intentToCharge = new Intent(this, KeyToOilActivity.class);
			intentToCharge.putExtra("paymethod", 1);
			startActivityIn(intentToCharge);
			break;
		default:
			break;
		}
	}

	public void getWallet() {
		/**
		 * 成功返回结果
		 */
		Listener<String> sL = new Response.Listener<String>() {
			@Override
			public void onResponse(String response) {

				dismissLoadingProgress();
				Log.i("TAG----success", response.toString());
				Gson gson = new Gson();
				WealthAccountJournalProfitStatistic wjps = gson.fromJson(
						response, WealthAccountJournalProfitStatistic.class);
				if (wjps.getWealthAccount().getLatestProfit() != null) {
					lastDay.setText(wjps.getWealthAccount().getLatestProfit()
							.doubleValue()
							+ "");
				} else {
					lastDay.setText("客官别急!");
				}

				if (wjps.getWealthAccount().getBalance() != null) {
					allMoney.setText(wjps.getWealthAccount().getBalance()
							.doubleValue()
							+ "");
				} else {
					lastDay.setText("您还没有余额!");
				}
				
				if(wjps.getJournalList().size()>0){
					MyWalletListAdapter madapter = new MyWalletListAdapter(MyWalletActivity.this, wjps.getJournalList(), wjps.getMaxProfit().doubleValue());
					mlist.setAdapter(madapter);
				}else{
					mlist.setVisibility(View.GONE);
//					meishuju.setVisibility(View.VISIBLE);
				}
			}
		};

		showLoadingProgress();
		String path = Config.URL_WEALTH_PROFIT;
		Map<String, String> map = new HashMap<String, String>();
		map.put("type", "1");
		Util.httpRequestToGetWithParams(path, sL, this, map);
	}

}
